package cn.javacc.common.web;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;

/**
 * 
 * @author mzh2008@163.com 2012-11-12 下午11:26:34
 * 
 */
public class ParamDecFilter implements Filter {

	public void destroy() {
	}

	public void doFilter(ServletRequest arg0, ServletResponse arg1, FilterChain arg2) throws IOException, ServletException {

		HttpServletRequest request = ((HttpServletRequest) arg0);
		request.setCharacterEncoding("UTF-8");
		// 此处使用自定义的JrHttpRequest包装原Request
		if (request.getParameter("encstr") != null || request.getRequestURI().startsWith(request.getContextPath() + "/port")) {
			arg2.doFilter(new JrHttpRequest((HttpServletRequest) arg0), arg1);
		} else {
			// System.err.println("name:" + request.getParameter("name"));
			arg2.doFilter(arg0, arg1);
		}

	}

	public void init(FilterConfig arg0) throws ServletException {

	}

}
